﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.IO;
using System.Drawing.Imaging;
using System.Data.SqlClient;
using System.Configuration;
using System.Data.Sql;
using System.Data.SqlTypes;
using System.Web.SessionState;
using System.ComponentModel;
using System.Data;
using System.Web.UI.HtmlControls;



namespace iResume
{
    public partial class recruiterUpdate : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                tbxCompanyN.Focus();

                ArrayList RecruiterUpdate = new ArrayList();
                string email = (string)(Session["username"]);
                if (email == null)
                {
                    Response.Redirect("loginpage.aspx");
                }
                RecruiterUpdate = DBManager.retrieveRecruiter(email);
                Recruiter rUpdate = new Recruiter();
                rUpdate = (Recruiter)RecruiterUpdate[0];
                //FileInfo info = new FileInfo(FileUploadImage.Value.Trim());
                //byte[] content = new byte[info.Length];
                //FileStream imagestream = info.OpenRead();
                //imagestream.Read(content, 0, content.Length);
                //imagestream.Close();
                Image2.ImageUrl = "recruiterDisplayImage.ashx?id=" + rUpdate.Email;
                tbxCompanyN.Text = rUpdate.CompanyName;
                tbxCompanyA.Text = rUpdate.CompanyAddress;
                tbxCompanyP.Text = rUpdate.CompanyProfile;
                tbxCompanyU.Text = rUpdate.CompanyURL;
                tbxN.Text = rUpdate.PersonInCharge;
                tbxE.Text = rUpdate.Email;
                tbxP.Text = rUpdate.Position;
                tbxD.Text = rUpdate.Department;
                tbxC.Text = rUpdate.ContactNum;
                tbxPostalCode.Text = rUpdate.PostalCode;


            }
        }

       

        protected void tbxN_TextChanged(object sender, EventArgs e)
        {

        }

        protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
        {
            string username = (string)(Session["username"]);
            string password = (string)(Session["password"]);
            string companyName = tbxCompanyN.Text;
            string companyAddress = tbxCompanyA.Text;
            string companyProfile = tbxCompanyP.Text;
            string companyURL = tbxCompanyU.Text;
            string personIncharge = tbxN.Text;
            string email = tbxE.Text;
            string position = tbxP.Text;
            string department = tbxD.Text;
            string contactNum = tbxC.Text;
            string postalCode = tbxPostalCode.Text;

            if (FileUploadImage.PostedFile.FileName != "")
            {
                FileInfo info = new FileInfo(FileUploadImage.PostedFile.ContentType);
                byte[] content = new byte[FileUploadImage.PostedFile.InputStream.Length + 1];
                FileUploadImage.PostedFile.InputStream.Read(content, 0, content.Length);


                Recruiter r = new Recruiter(companyName, companyAddress, companyProfile, personIncharge, email, contactNum, companyURL, position, department, content, postalCode);

                DBManager.updateRecruiter(r);

                tbxCompanyN.Text = "";
                tbxCompanyA.Text = "";
                tbxC.Text = "";
                tbxCompanyP.Text = "";
                tbxCompanyU.Text = "";
                tbxD.Text = "";
                tbxE.Text = "";
                tbxN.Text = "";
                tbxP.Text = "";

                Response.Redirect("recruiterView.aspx");
            }
            else
            {
                              

                Recruiter r = new Recruiter(companyName, companyAddress, companyProfile, personIncharge, email, contactNum, companyURL, position, department, null, postalCode);

                DBManager.updateRecruiter1(r);

                tbxCompanyN.Text = "";
                tbxCompanyA.Text = "";
                tbxC.Text = "";
                tbxCompanyP.Text = "";
                tbxCompanyU.Text = "";
                tbxD.Text = "";
                tbxE.Text = "";
                tbxN.Text = "";
                tbxP.Text = "";

                Response.Redirect("recruiterView.aspx");

            }
        }
    }
}